package com.fengye.cluster;

import org.apache.commons.lang.StringUtils;

/**
 * @Author fengye
 * @Date 2023/2/15 13:34
 **/
public enum ClusterStrategyEnum {

    /** 随机 */
    RANDOM("Random"),

    /** 加权随机 */
    WEIGHT_RANDOM("WeightRandom"),

    /** 轮询 */
    POLLING("Polling"),
    /** 加权轮询 */
    WEIGHT_POLLING("WeightPolling"),
    /** 哈希 */
    HASH("Hash")
    ;

    private ClusterStrategyEnum(String code) {
        this.code = code;
    }

    /**
     * 获取ClusterStrategyEnum
     * @param code
     * @return
     */
    public static ClusterStrategyEnum queryByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }

        for (ClusterStrategyEnum strategy : values()) {
            if (StringUtils.equals(code, strategy.getCode())) {
                return strategy;
            }
        }
        return null;
    }

    private String code;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}
